﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Web;
namespace HXDNB.Infrastructure
{
    public class Paging<T>
    {
        //总记录数
        private int allCount = 0;
        public int AllCount
        {
            get { return allCount; }
            set { allCount = value; }
        }
        //当前页码
        private int pageIndex = 1;
        public int PageIndex
        {
            get
            {
                if (string.IsNullOrWhiteSpace(HttpContext.Current.Request["PageIndex"]) == false)
                {
                    pageIndex = int.Parse(HttpContext.Current.Request["PageIndex"]);
                }
                return pageIndex <= 0 ? 1 : pageIndex;
            }
            set { pageIndex = value; }
        }
        //每页显示数量
        private int pagesize = 10;
        public int PageSize
        {
            get
            {
                if (string.IsNullOrWhiteSpace(HttpContext.Current.Request["PageSize"]) == false)
                {
                    pagesize = int.Parse(HttpContext.Current.Request["PageSize"]);
                }
                return pagesize;
            }
            set { pagesize = value; }
        }
        //数据源
        public IQueryable<T> DataList { get; set; }
        //构造函数
        public Paging(int index, IQueryable<T> Data)
        {
            this.PageIndex = index;
            this.DataList = Data.Skip((PageIndex - 1) * PageSize).Take(PageSize);
            this.AllCount = Data.Count();
        }
        //构造函数
        public Paging(int index, IQueryable<T> Data, int PageSize)
        {
            this.PageIndex = index;
            this.pagesize = PageSize;
            this.DataList = Data.Skip((PageIndex - 1) * PageSize).Take(PageSize);
            this.AllCount = Data.Count();
        }
    }
}
